<?php
	class PermissionAction extends BaseAction{
		public function index(){
			$permission = M('Permission');
			import('ORG.Util.Page');
			$count = $permission->count();
			$page = new Page($count,c('PAGESIZE'));
			$show = $page->show();
			$data = $permission->field(true)
						->limit($page->firstRow.','.$page->listRows)
						->select();
			$this->assign('permission',$data);
			$this->assign('page',$show);
			$this->display();
		}
		
		public function add(){
			$this->display();
		}
		
		public function insert(){
			$permission = D('Permission');
			if($data = $permission->create()){
				if($permission->add()){
					$this->success('新增权限成功！');
				}else{
					$this->error('新增权限失败！');
				}
			}else{
				$this->error($permission->getError());
			}	
		}
		
		public function edit(){
			if(!empty($_GET['id'])){
				$permission = M('Permission');
				$data = $permission->field(true)
									->getById($_GET['id']);
				if(null == $data)
					$this->error('请确保权限ID合法！');
				$this->assign('permission',$data);
				$this->display();
			}else{
				$this->error('请选择要修改的权限！');
			}
		}
		
		public function update(){
			$permission = D('Permission');
			if($permission->create()){
				if($permission->save()){
					$this->success('修改权限成功！');
				}else{
					$this->error('数据没有变化或修改权限失败！');
				}
			}else{
				$this->error($permission->getError());
			}
		}
		
		public function delete(){
			if(!empty($_GET['id'])){
				$permission = M('Permission');
				if($permission->delete($_GET['id'])){
					$this->success('删除权限成功！');
				}else{
					$this->error('删除权限失败！');
				}
			}else{
					$this->error('请选择要删除的权限！');
			}
		}
	}
?>